#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
交易 - 预授权查询功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.trans.common.pre_auth_query_service import PreAuthQueryService
from jlpay.model.trans.common.common_trans import PreAuthQueryRequest


class PreAuthQueryExample(BaseExample):
    """预授权查询示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.trans.common.pre_auth_query")
        self.service = PreAuthQueryService(self.config)
    
    def build_pre_auth_query_request(self):
        """
        构建预授权查询请求
        
        Returns:
            PreAuthQueryRequest实例
        """
        request = PreAuthQueryRequest()
        
        # 设置请求参数
        request.set_mch_id("849584358120018")
        request.set_out_trade_no("ld201911023465529")
        request.set_transaction_id("80011557201909171853011568")
        
        return request
    
    def demo(self):
        """执行预授权查询示例"""
        self.logger.info("开始执行预授权查询示例")
        
        # 创建预授权查询请求
        request = self.build_pre_auth_query_request()
        
        # 发送请求
        self.send_request_and_handle_response(
            self.service.pre_auth_query,
            "预授权查询",
            request
        )
        
        self.logger.info("预授权查询示例执行完毕")


if __name__ == "__main__":
    logger = PreAuthQueryExample().logger
    logger.info("=" * 50)
    logger.info("===== 预授权查询示例 开始 =====")
    logger.info("=" * 50)
    
    example = PreAuthQueryExample()
    example.demo()
    
    logger.info("=" * 50)
    logger.info("===== 预授权查询示例执行完毕 =====")
    logger.info("=" * 50) 